package view.panel.play
{
	import control.panel.AddFriendPanelControl;
	import control.panel.IPanelControl;
	
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import model.role.IRoleData;
	
	import utils.TextTool;
	
	import view.components.ImgButton;
	import view.components.RemoteHtmlImg;
	import view.panel.AbsPanel;
	
	import global.GameState;
	
	public class SelfInfoPanel extends AbsPanel
	{
		private var headImg:RemoteHtmlImg;
		private var useBut:ImgButton;
		private var homeBut:ImgButton;
		
		private var nameText:TextField;
		private var moneyText:TextField;
		private var homeText:TextField;
		
		public function SelfInfoPanel(panelControl:IPanelControl)
		{
			super(panelControl);
			resetBg(263,116,1,true);
			initCloseBut();
			resetCloseBut();
			dropShadow();
			initTweenPanelOpen();
			
			initHeadImg();
			initBut();
			initText();
		}
		
		private function initText():void
		{
			nameText = TextTool.getTextFieldXY(110,16,100,20,14,0xFFFFFF,"",false,true);
			addChild(nameText);
			
			moneyText = TextTool.getTextFieldXY(110,36,100,20,12,0xFFFF00,"");
			addChild(moneyText);
			
			homeText = TextTool.getTextFieldXY(110,56,100,20,12,0xFFFFFF,"");
			addChild(homeText);
		}
		
		private function initBut():void
		{
			useBut = new ImgButton(62,80,0,onBut,70,22,"butBg",null,"使用道具");
			addChild(useBut);
			
			if (GameState.sns != "2")
			{
				homeBut = new ImgButton(140,80,1,onBut,70,22,"butBg",null,"个人主页");
				addChild(homeBut);
			}
		}
		
		public function update(data:IRoleData):void
		{
			headImg.loadImg(data.imgUrl);
			nameText.text = data.roleName;
			moneyText.text = "$" + data.money;
			homeText.text = "来自:" + data.snsName;
		}
		
		private function onBut(event:MouseEvent):void
		{
			switch (event.target.id)
			{
				case 0:
					(panelControl as AddFriendPanelControl).itemUse();
					break;
				case 1:
					
					if (GameState.sns != "2")
					{
						(panelControl as AddFriendPanelControl).goHomePage();
					}
					break;
			}
		}
		
		private function initHeadImg():void
		{
			headImg = new RemoteHtmlImg(50,50);
			headImg.x = 28;
			headImg.y = 16;
			addChild(headImg);
		}
		
		
		
		
	}
}